import request from './axios'

function getReportData() {
  return request.get('/reportdata').then(res => {
   // console.log(res.data)
    return res.data
  })
}

export function ShowReportData() {
 const data= getReportData().then(res => {
    //console.log(res)
    return [{
      HeaderName: '累计销售额',
      HeaderNum: res.salesToday,
      content: [{ title: '同日比', value: res.salesGrowLastDay }, { title: '同月比', value: res.saleSGrowLastMonth }],
      option: '',
      FooterTitle: '昨日销售额',
      FooterNum: res.salesLastDay,
      FooterTest: false,
    }, {
      HeaderName: '累计订单额',
      HeaderNum: res.orderToday,
      content:false,
      option: {
        xAxis: {
          show: false,
          type: 'category',
          data: [0, 1, 2, 3, 4, 5, 6, 7],
          boundaryGap: false,//清楚距离x轴的默认间距
        },
        yAxis: {
          boundaryGap:['0%','0%'],
          type: 'value',
          show: false,

        },
        series: [
          {
            data: res.orderTrend,
            type: 'line',
            areaStyle: {
              color: 'purple'
            },
            lineStyle: {
              opacity: 0,
            },
            symbol: 'none',
            smooth: true,
          }
        ],
        grid: {
          top: '0',
          left: '0',
          right: '0',
          bottom: '0',
        }
      },
      FooterTitle: '昨日销售额',
      FooterNum: res.orderLastDay,
      FooterTest: false,
    }, {

      HeaderName: '今日用户交易数',
      HeaderNum: res.userToday,
      content: false,
      option: {
        xAxis: {
          show: false,
          type: 'category',
          data: ["00:00", "03:00", "05:00", "07:00", "09:00", "11:00", "13:00", "15:00", "17:00", "19:00", "21:00", "23:00"]
        },
        yAxis: {
          type: 'value',
          show: false,
        },
        series: [
          {
            name: '实时交易量',
            data: res.orderUserTrend,
            type: 'bar',
          },
        ],
        grid: {
          top: '0',
          left: '0',
          right: '0',
          bottom: '0',
        },
        tooltip: {

        }
      },
      FooterTitle: '退货率',
      FooterNum: res.returnRate,
      FooterTest: false,
    }, {

      HeaderName: '累计用户数',
      HeaderNum: res.totalUser,
      content: false,
      option: {
        xAxis: {
          show: false,
          type: 'value',
        },
        yAxis: {

          show: false,
          type: 'category',

        },
        series:[{
          data: [res.userLastMonth],
          type: 'bar',
          //showBackground: true,
          color: 'green',
          stack: '总量',
          barWidth: 10,
        },{
          data: [50],
          type: 'bar',
          //showBackground: true,
          color: '#e0e0e0',
          stack: '总量',
        },
        {
          type:'custom',//自定义系列可以自定义系列中的图形元素渲染。从而能扩展出不同的图表。
          //开发者自定义渲染逻辑（renderItem 函数）
          //params：包含了当前数据信息和坐标系的信息。
          //api：是一些开发者可调用的方法集合。
          data: [130],
          renderItem: function (params, api) {
            //获取点位置
            const endPoint = api.coord([api.value(0), 0]);
            return{
              type:'group',//如果是一个就是该点的类型,多个就是group+children。
              children: [
                {
                  type:'path',//svg类型
                  shape: {
                    d: "M511.744 319.999l-383.744 383.744h767.488l-383.744-383.744z",//
                    x: endPoint[0] - 5,
                    y: 35,
                    width: 10,
                    height: 10,
                    layout: "cover",
                  },
                  style:{
                    fill:'green'
                  },
                },{
                  type:'path',//svg类型
                  shape: {
                    d: "M889.696 320.8H158.848l365.504 365.536 365.344-365.536z",
                    x: endPoint[0] - 5,
                    y: 5,
                    width: 10,
                    height: 10,
                    layout: "cover",
                  },
                  style:{
                    fill:'green'
                  },
                }
              ]
            }
          }
        }
      ],

        grid: {
          top: '0',
          left: '0',
          right: '0',
          bottom: '0',
        },
        

      },
      FooterTitle: '',
      FooterNum: '',
      FooterTest: [{ title: '日同比', value: res.userGrowLastDay }, { title: '月同比', value: res.userGrowLastMonth }],
    }
    ]
  })
  return data
}